package com.lc.afbx.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiBaoXianJiFen;

import java.util.List;

/**
 * Created by Administrator on 2016/6/6.
 */
public class BaoXianJiFenAdapter extends BaseAdapter {
    private List<GetApiBaoXianJiFen.Detail> detailList;
    private LayoutInflater inflater;

    public BaoXianJiFenAdapter(Context context, List<GetApiBaoXianJiFen.Detail> detailList) {
        this.detailList = detailList;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return detailList.size();
    }

    @Override
    public Object getItem(int position) {
        return detailList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_baoxianjifen, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);

            holder = new ViewHolder();
            holder.txt1 = (TextView) convertView.findViewById(R.id.txt1);
            holder.date = (TextView) convertView.findViewById(R.id.txt_riqi);
            holder.youXiaoDate = (TextView) convertView.findViewById(R.id.txt_youxiaoriqi);
            holder.jiFen = (TextView) convertView.findViewById(R.id.txt_jifen);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.txt1.setText(detailList.get(position).insurance_type);
        holder.date.setText(detailList.get(position).posttime);

        String str = detailList.get(position).indate;

        String[] aa = str.split(" ");

        holder.youXiaoDate.setText("有效期至" + aa[0]);
        holder.jiFen.setText(detailList.get(position).integral);

        return convertView;
    }

    class ViewHolder {

        TextView txt1, date, youXiaoDate, jiFen;
    }
}
